package cn.edu.gsau.info.controller;
import cn.edu.gsau.info.models.*;
import cn.edu.gsau.info.service.IHuojiangService;
import cn.edu.gsau.info.util.UploadUtil;
import cn.edu.gsau.info.vo.Params;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: ltl
 * @date: 2022/11/19
 * @param:
 * @return:
 **/
@RestController
@RequestMapping("/huojiang")
@JsonSerialize(using = ToStringSerializer.class)
public class HuojiangController {
    @Autowired
    IHuojiangService iHuojiangService;

    @Value("${gsau.upload.path}")
    private String path;

    /**
     * @description:文件上传控制器
     * @author: ltl
     * @date: 2022/11/23
     * @param: 文件
     * @return: 存放旧文件名和uuid生成的新文件名
     **/
    @PostMapping("/upload")
    public ResponseResult upload(@RequestBody MultipartFile file){
        User user =new User();
        user.setUserName("liumaobing");
        UploadUtil upload = new UploadUtil();
        Map<String, String> map = upload.filedUpload(file, user.getUserName(), path);
        return new ResponseResult(Code.SAVE_OK,"文件上传成功",map);
    }

    /**
     * @description:添加获奖信息
     * @author: ltl
     * @date:2022、11、23
     * @param: 表单对象
     * @return: 无
     **/
    @PostMapping("addinfo")
    public ResponseResult addInfo(@RequestBody Huojiang huojiang){
        User user = new User();
        user.setId(1L);
        user.setUserName("liumaobing");
        iHuojiangService.addInfo(user,huojiang);
        return new ResponseResult(Code.SAVE_OK,"添加成功");
    }
    /**
     * @description:通过主键id删除数据
     * @author: ltl
     * @date: 2022/11/22
     * @param: id 主键值
     * @return: null
     **/
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        iHuojiangService.delete(id);
        return new ResponseResult(Code.DELETE_OK,"删除成功",null);
    }

    /**
     * @description:修改获奖信息
     * @author: ltl
     * @date: 2022/11/26
     * @param: 表单数据
     * @return: 无
     **/
    @PutMapping("/update")
    public ResponseResult updateShuJu(@RequestBody Huojiang huojiang){
        User user = new User();
        user.setId(1l);
        user.setNickName("刘茂兵");
        iHuojiangService.updateShuJu(user,huojiang);
        return new ResponseResult(Code.UPDATE_OK,"修改成功",null);
    }

    /**
     * @description:通过条件查询数据
     * @author: ltl
     * @date: 2022/11/22
     * @param: params对象
     * @return: 满足条件的集合
     **/
    @PostMapping("/selectbycondation")
    public ResponseResult<Huojiang> selectByCondation(@RequestBody Params params){
        List<Huojiang> list =  iHuojiangService.selectByCondation(params);
        return new ResponseResult(Code.GET_OK,"查询成功",list);
    }

    /**
     * @description:通过主键id查找对应的数据
     * @author: ltl
     * @date: 2022/11/22
     * @param: id 主键值id
     * @return: id 那一行的数据
     **/
    @GetMapping("selectone/{id}")
    public ResponseResult selectOne(@PathVariable long id){
       Huojiang huojiang = iHuojiangService.selectOne(id);
       return new ResponseResult(Code.GET_OK,"查询成功",huojiang);
    }

    @GetMapping("selectshenghe/{page}")
    public ResponseResult selectShengHe(@PathVariable Integer page){
        User user = new User();
        user.setId(9l);
        user.setNickName("孙静伟");
        List list = iHuojiangService.selectShengHe(user,page);
        return new ResponseResult(Code.GET_OK,"查询成功",list);
    }
    /**
     * @description: 通过模块id和记录数id找到审核的记录，并添加审核意见和修改节点
     * @author: ltl
     * @date: 2022/11/29
     * @param:shenhe 审核意见，记录数id，节点
     * @return:无
     **/
    @PostMapping("addshemhe")
    public ResponseResult UpdateYiJianAndNote(@RequestBody Shenhe shenhe){
        iHuojiangService.UpdateYiJianAndNote(shenhe);
        return new ResponseResult(Code.SAVE_OK,"添加及修改成功");
    }
    /**
     * @description:通过模块id和记录数id、memo查询审核流程
     * @author: ltl
     * @date:  2022、11、29
     * @param: 记录数id
     * @return: 审核流程的集合
     **/
    @GetMapping("selectliucheng/{id}")
    public ResponseResult selectLiuCheng(@PathVariable Long id){
        List list = iHuojiangService.selectLiuCheng(id);
        return new ResponseResult(Code.GET_OK,"查询成功",list);
    }
//    /**
//     * @description:查找证明材料
//     * @author: ltl
//     * @date: 2022/11/24
//     * @param: 获奖表名、自增长id
//     * @return: 证明材料的集合
//     **/
//    @GetMapping("/selectZhengMingCaiLiao/{id}")
//    public ResponseResult selectZMCL(@PathVariable Long id){
//        List list =  iHuojiangService.selectZMCL(id);
//        return new ResponseResult(200,"查询成功",list);
//    }
    /**
     * @description: 通过填报人查询获奖信息
     * @author: ltl
     * @date: 2022/11/20
     * @param: 填表人
     * @return: 填表人的获奖信息
     **/
//    @GetMapping("/find/{id}")
//    public ResponseResult findById(@PathVariable Integer id){
//        User user = new User();
//        user.setId(1L);
//        user.setUserName("刘茂兵");
//        Huojiang huojiang = new Huojiang();
//        huojiang.setTianbaoId(user.getId());
//        List<Huojiang> list =  iHuojiangService.selectById(huojiang);
//        return new ResponseResult(Code.GET_OK,"查询成功",list);
//    }
    /**
     * @description:查询所有的获奖情况
     * @author: ltl
     * @date: 2022/11/20
     * @param: 无
     * @return: 查询所有的获奖情况
     **/
//    @GetMapping("findall")
//    public ResponseResult findAll(){
//        List<Huojiang> list =  iHuojiangService.selectAll();
//        return new ResponseResult(list==null?Code.GET_ERR:Code.GET_OK,list==null?"查询失败":"查询成功",list);
//    }

}

